/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.svh.Entidad;

import java.io.Serializable;
import java.util.Comparator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author user
 */
@Entity
@Table(name = "Permiso")
public class Permiso implements Serializable, Comparable<Permiso>{
    @Id
    @GeneratedValue
    @Column(name = "IDPERMISO")
    Integer id;
    
    @ManyToOne
    @JoinColumn(name = "IDPERFIL", nullable = false)        
    Perfil perfil;
    
    @ManyToOne
    @JoinColumn(name = "IDMODULO", nullable = false)
    Modulo modulo;
    
    @Column(name = "CREAR")
    Boolean crear;
    
    @Column(name = "LISTAR")
    Boolean listar;
    
    @Column(name = "ACTUALIZAR")
    Boolean actualizar;
    
    @Column(name = "ELIMINAR")
    Boolean eliminar;

    public Permiso() {
    }
    
    

    public Permiso(Integer id, Perfil perfil, Boolean crear, Boolean listar, Boolean actualizar, Boolean eliminar) {
        this.id = id;
        this.perfil = perfil;
        this.crear = crear;
        this.listar = listar;
        this.actualizar = actualizar;
        this.eliminar = eliminar;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Perfil getPerfil() {
        return perfil;
    }

    public void setPerfil(Perfil perfil) {
        this.perfil = perfil;
    }

    public Boolean getCrear() {
        return crear;
    }

    public void setCrear(Boolean crear) {
        this.crear = crear;
    }

    public Boolean getListar() {
        return listar;
    }

    public void setListar(Boolean listar) {
        this.listar = listar;
    }

    public Boolean getActualizar() {
        return actualizar;
    }

    public void setActualizar(Boolean actualizar) {
        this.actualizar = actualizar;
    }

    public Boolean getEliminar() {
        return eliminar;
    }

    public void setEliminar(Boolean eliminar) {
        this.eliminar = eliminar;
    }

    public Modulo getModulo() {
        return modulo;
    }

    public void setModulo(Modulo modulo) {
        this.modulo = modulo;
    }

   
    @Override
    public int compareTo(Permiso o) {
        int idClase = this.getModulo().getId();
        if(idClase < o.getModulo().getId()){
            return -1;
        }else{
            return 1;
        }
    }
    
    @Transient
    public static Comparator<Permiso> compararPermisos = new Comparator<Permiso>() {

        @Override
        public int compare(Permiso o1, Permiso o2) {
            return o1.compareTo(o2);
        }
    };
     
}
